import {
  http
} from '../../http/index';
let globalData = getApp().globalData;
Page({
  data: {
    carouselData: [],
    petData: [],
    categoryData: [],
    token: null,
    userInfo: {},
    globalData,
    active: '全部',
  },
  onChange(event) {
    this.setData({ active: event.detail.name });
    this.getPet(true)
  },
  getPet(loading) {
    if (loading) {
      wx.showLoading();
    }
    http({
      url: '/pet/list',
      data: {
        category: this.data.active,
        status: 0
      }
    }).then(({
      data
    }) => {
      this.setData({
        petData: data.result
      });
      wx.hideLoading()
    });
  },
  getList() {
    wx.showLoading()
    http({
      url: '/carousel/list',
    }).then(({
      data
    }) => {
      this.setData({
        carouselData: data.result
      });
    }).then(() => {
      http({
        url: '/category/list',
      }).then(({
        data
      }) => {
        this.setData({
          categoryData: data.result
        });
      })
    })
  },
  goKnowledge() {
    wx.navigateTo({
      url: '/pages/knowledge/index',
    });
  },
  goPost() {
    wx.switchTab({
      url: '/view/post/index',
    })
  },
  goDetails(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/petDetails/index' + '?id=' + id,
    });
  },
  onLoad() {
    this.getList();
  },
  onShow() {
    this.getPet(false);
  },
})